﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace _13_webAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Persons : ControllerBase
    {
        [HttpGet]
        public Models.Person[] GetAll()
        {
            return new Models.Person[] {
                new Models.Person(1,"aggie",18),
                new Models.Person(2,"Tom",5)
            };
        }
        [HttpGet]
        public Models.Person? GetById(int id)
        {
            if (id == 1)
            {
                return new Models.Person(1, "aggie", 18);
            }
            else if (id == 2)
            {
                return new Models.Person(2, "Tom", 5);
            }
            else {
                return null;
            }
        }
        [HttpPost] 
        public string AddNew(Models.Person p)
        {
            return "搞定"; 
        }
    }
}
